package control

import (
	"fmt"
	"net/http"
	"pro_cla_sql/model"
	"pro_cla_sql/util"
	"strconv"
)

func Sleave(w http.ResponseWriter, r *http.Request) {
	w.Header().Set(`Content-Type`, `application/json`)
	w.Header().Set(`Access-Control-Allow-Origin`, `*`)
	cid := CSno[0:10]
	println(cid[0:10])
	// print(sno)
	mod, err := model.SleavesAll(cid)
	if err != nil {
		w.Write(util.NewResult(util.Fail, "请假信息查询失败"))
		return
	} else {
		w.Write(util.NewResult(util.Success, "请假信息查询成功", mod))
		return
	}

}

func Sleavesadd(w http.ResponseWriter, r *http.Request) {
	w.Header().Set(`Content-Type`, `application/json`)
	w.Header().Set(`Access-Control-Allow-Origin`, `*`)

	r.ParseForm()
	// map
	var sno = CSno

	_, sname, sex, tel, _, _ := model.SinfosOne(sno)
	fmt.Println(sex)
	var content = r.FormValue("reason")

	acid := sno[0:10]
	cid, _ := strconv.Atoi(acid)
	_, a, m, g, c, _ := model.CinfosOne(cid)
	fmt.Println(a, m, g, c, "+++++++++++++")
	ok := model.Sleaveadd(sname, a, m, tel, g, c, content, cid)
	if ok {
		w.Write(util.NewResult(util.Success, "申请成功"))
	} else {
		w.Write(util.NewResult(util.Fail, "申请失败"))
	}

}
